package com.cheyun.netsalev3.widget

import android.app.Dialog
import android.app.TimePickerDialog
import android.os.Bundle
import android.text.format.DateFormat
import android.widget.TimePicker
import androidx.fragment.app.DialogFragment
import java.util.*
import kotlin.reflect.KFunction3

class TimePickerFragment : DialogFragment(), TimePickerDialog.OnTimeSetListener {
    var clickOk: KFunction3<@ParameterName(name = "view")
    TimePicker, @ParameterName(name = "hourOfDay") Int,
            @ParameterName(name = "minute") Int, Unit>? = null

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        //使用当前时间作为选取器的默认值
        val c = Calendar.getInstance()
        val hour = c.get(Calendar.HOUR_OF_DAY)
        val minute = c.get(Calendar.MINUTE)
        //创建TimePickerDialog的新实例并返回它
        return TimePickerDialog(activity, this, hour, minute, DateFormat.is24HourFormat(activity))
    }

    override fun onTimeSet(view: TimePicker, hourOfDay: Int, minute: Int) {
        //根据用户选择的时间做一些事情
        clickOk?.apply {
            this(view, hourOfDay, minute)
        }
    }
}